package cn.com.code.generator.controller;

import cn.com.code.generator.entity.ProcessStatistic;
import cn.com.code.generator.service.ProcessStatisticService;
import cn.com.do1.dsf.common.annotation.SysLog;
import cn.com.do1.dsf.common.validator.group.AddGroup;
import cn.com.do1.dsf.common.validator.group.UpdateGroup;
import cn.com.do1.dsf.common.web.BaseRestController;
import cn.com.do1.dsf.compont.mysql.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.Map;


/**
 * 流程统计
 *
 * @author nick
 * @email sunlightcs@gmail.com
 * @date 2021-05-01 17:14:53
 */
@Api(tags = "流程统计")
@RestController
@RequestMapping("/process/statistic")
public class ProcessStatisticController extends BaseRestController {
    @Autowired
    private ProcessStatisticService processStatisticService;

    /**
     * 列表
     */
    @GetMapping("/")
    @ApiOperation("查询流程统计列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appName", value="应用名称", paramType = "query"),
            @ApiImplicitParam(name = "deptName", value="部门名称", paramType = "query"),
            @ApiImplicitParam(name = "assigneeName", value="执行人名称", paramType = "query"),
            @ApiImplicitParam(name = "processDefinitionName", value="流程定义名称", paramType = "query"),
            @ApiImplicitParam(name = "taskName", value="任务名称", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value="任务开始时间", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value="任务结束时候", paramType = "query"),
            @ApiImplicitParam(name = "duration", value="历时（单位秒）", paramType = "query"),
            @ApiImplicitParam(name = "appKey", value="", paramType = "query"),
            @ApiImplicitParam(name = "annual", value="", paramType = "query"),
            @ApiImplicitParam(name = "page", value="页码", paramType = "query" ,required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "limit", value="每页条数", paramType = "query",required = true, defaultValue = "10"),
            @ApiImplicitParam(name = "sidx", value="排序字段", paramType = "query"),
            @ApiImplicitParam(name = "order", value="排序方式，如：asc、desc",  paramType = "query")
    })
    public PageUtils<ProcessStatistic> list(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils<ProcessStatistic> page = processStatisticService.queryPage(params);

        return page;
    }


    /**
     * 信息
     */
    @GetMapping("/{id}")
    @ApiOperation("获取流程统计信息")
    @ApiImplicitParam(name = "id", value = "ID",paramType="path", required = true)
    public ProcessStatistic info(@PathVariable("id") Long id){
		ProcessStatistic processStatistic = processStatisticService.selectById(id);

        return processStatistic;
    }

    /**
     * 保存
     */
    @SysLog("保存流程统计")
    @PostMapping("/")
    @ApiOperation("保存流程统计")
    public ProcessStatistic save(@Validated(AddGroup.class) @RequestBody ProcessStatistic processStatistic){
        processStatisticService.insert(processStatistic);

        return processStatistic;
    }

    /**
     * 修改
     */
    @SysLog("修改流程统计")
    @PutMapping("/{id}")
    @ApiOperation("修改流程统计")
    public ProcessStatistic update(@Validated(UpdateGroup.class) @RequestBody ProcessStatistic processStatistic){
		processStatisticService.updateById(processStatistic);

        return processStatistic;
    }

    /**
     * 删除
     */
    @SysLog("删除流程统计")
    @DeleteMapping("/")
    @ApiOperation("删除流程统计")
    public void delete(@RequestBody Long[] ids){
		processStatisticService.deleteBatchIds(Arrays.asList(ids));

    }

}
